﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Vroom.TableListener.Model
{
	public class MainModel
	{
		public string ConnString { get; set; }

		public MainModel(string connString)
		{
			ConnString = connString;
		}


		public IEnumerable<DataSource> GetRows()
		{
			using (var connection = new SqlConnection(ConnString))
			{
				using (var cmd = connection.CreateCommand())
				{
					cmd.CommandText = "SELECT TOP 100000 Yield, Duration FROM fact.[Fact Risk Metrics] (NOLOCK) WHERE Yield IS NOT NULL AND Duration IS NOT NULL";
					connection.Open();

					var reader = cmd.ExecuteReader();

					using (reader)
					{
						while (reader.Read())
						{							
							var datasource = new DataSource
							{
								Name		= reader.GetDouble(0).ToString(),
								Description = reader.GetDouble(1).ToString()

							};

							yield return datasource;
						}
					}
				}
			}

		}
	}
}

